package logic

import (
	"context"
	"errors"
	"local-life/model"

	"local-life/liferpc/internal/svc"
	"local-life/liferpc/liferpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type StoreAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewStoreAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *StoreAddLogic {
	return &StoreAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *StoreAddLogic) StoreAdd(in *liferpc.StoreAddRequest) (*liferpc.StoreAddResponse, error) {
	// todo: add your logic here and delete this line
	stores := model.Store{
		UserID:  in.UserID,
		Name:    in.Name,
		Address: in.Address,
		Phone:   in.Phone,
		Price:   float64(in.Price),
		Image:   in.Image,
	}
	err := stores.StoreCreate(model.DB)
	if err != nil {
		return nil, errors.New("商家入驻失败")
	}
	return &liferpc.StoreAddResponse{
		StoreID: int64(stores.ID),
	}, nil
}
